﻿using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Volo.Abp;

namespace CTP.CRM.Core.SharedModel.Pub
{
    //
    // 摘要:
    //     ThrowHelper
    public sealed class ThrowHelper
    {
        //
        // 摘要:
        //     value:null => halt
        //
        // 参数:
        //   argument:
        //
        //   throwMessage:
        //
        //   memberName:
        //
        //   sourceLineNumber:
        //
        //   paramName:
        //
        // 异常:
        //   T:Volo.Abp.BusinessException:
        public static void ThrowIfNull([NotNull] object argument, string throwMessage, [CallerMemberName] string memberName = "", [CallerLineNumber] int sourceLineNumber = 0, [CallerArgumentExpression("argument")] string paramName = null)
        {
            if (argument == null)
            {
                throw new BusinessException(null, throwMessage);
            }
        }

        //
        // 摘要:
        //     value:null || empty || WhiteSpace => halt
        //
        // 参数:
        //   argument:
        //
        //   throwMessage:
        //
        //   memberName:
        //
        //   sourceLineNumber:
        //
        //   paramName:
        //
        // 异常:
        //   T:Volo.Abp.BusinessException:
        public static void ThrowIfEmpty(string argument, string throwMessage, [CallerMemberName] string memberName = "", [CallerLineNumber] int sourceLineNumber = 0, [CallerArgumentExpression("argument")] string paramName = null)
        {
            if (argument.IsNullOrEmpty() || argument.IsNullOrWhiteSpace())
            {
                throw new BusinessException(null, throwMessage);
            }
        }

        //
        // 摘要:
        //     value:true => halt
        //
        // 参数:
        //   codition:
        //
        //   throwMessage:
        //
        //   memberName:
        //
        //   sourceLineNumber:
        //
        //   paramName:
        //
        // 异常:
        //   T:Volo.Abp.BusinessException:
        public static void ThrowIfCodition(bool codition, string throwMessage, [CallerMemberName] string memberName = "", [CallerLineNumber] int sourceLineNumber = 0, [CallerArgumentExpression("codition")] string paramName = null)
        {
            if (codition)
            {
                throw new BusinessException(null, throwMessage);
            }
        }

        //
        // 摘要:
        //     value:false => halt
        //
        // 参数:
        //   codition:
        //
        //   throwMessage:
        //
        //   memberName:
        //
        //   sourceLineNumber:
        //
        //   paramName:
        //
        // 异常:
        //   T:Volo.Abp.BusinessException:
        public static void ThrowIfNotCodition(bool codition, string throwMessage, [CallerMemberName] string memberName = "", [CallerLineNumber] int sourceLineNumber = 0, [CallerArgumentExpression("codition")] string paramName = null)
        {
            if (!codition)
            {
                throw new BusinessException(null, throwMessage);
            }
        }

        public static void ThrowMessage(string throwMessage, [CallerMemberName] string memberName = "", [CallerLineNumber] int sourceLineNumber = 0, [CallerArgumentExpression("codition")] string paramName = null)
        {
            throw new BusinessException(null, throwMessage);
        }

        [Conditional("DEBUG")]
        public static void OutputDebugDetail(string message)
        {
            throw new BusinessException(null, message);
        }
    }
}
